package sorting;

public class SelectionSorting extends Sorting{

    private int[] datas;
    
    public SelectionSorting() {
        super();
    }
    
    public SelectionSorting(int[] datas) {
        super(datas);
        this.datas = datas;
    }
    
    public void sort() {
        for (int i = 0; i < datas.length; i++) {
            int minIndex = i;
            for (int j = i + 1; j < datas.length; j++) {
                if (datas[minIndex] > datas[j]) {
                    minIndex = j;
                }
            }
            if (i != minIndex) {
                swap(i, minIndex);
            } else if ( i <= minIndex) {
                return;
            }
        }
    }
    
    private void swap(int one, int two) {
        int temp = datas[one];
        datas[one] = datas[two];
        datas[two] = temp;
    }
    
    
}
